package com.xuqm.sdhbwfu.app.ui.adapter

import android.graphics.Color
import com.xuqm.base.adapter.BaseNormalAdapter
import com.xuqm.base.adapter.ItemViewDelegate
import com.xuqm.base.adapter.ViewHolder
import com.xuqm.sdhbwfu.app.MyApplication
import com.xuqm.sdhbwfu.app.R
import com.xuqm.sdhbwfu.app.model.PmTaskContent

class MaintainAdapter : BaseNormalAdapter<PmTaskContent>() {


    init {
        addItemViewDelegate(object : ItemViewDelegate<PmTaskContent> {
            override fun getItemViewLayoutId(): Int = R.layout.item_maintain_1

            override fun isForViewType(item: PmTaskContent, position: Int): Boolean =
                "COMPLETE" == item.taskStepExcuteStatus && "签字确认" != item.type

            override fun convert(holder: ViewHolder, t: PmTaskContent, position: Int) {
                holder.setText(R.id.item_maintain_1_index, "${position + 1}")
                holder.setText(R.id.item_maintain_1_title, t.title)
//                if (t.status.isNullOrEmpty()) {
                holder.setText(R.id.item_maintain_1_status, "正常")
                holder.setText(R.id.item_maintain_1_status_tv, "")
                holder.setBackgroundResource(
                    R.id.item_maintain_1_status,
                    R.drawable.maintain_status_normal
                )
                holder.setTextColor(R.id.item_maintain_1_status, Color.parseColor("#5ea978"))
//                } else {
//                    holder.setText(R.id.item_maintain_1_status, "异常")
//                    holder.setText(R.id.item_maintain_1_status_tv, t.status)
//                    holder.setBackgroundResource(
//                        R.id.item_maintain_1_status,
//                        R.drawable.maintain_status_err
//                    )
//                    holder.setTextColor(R.id.item_maintain_1_status, Color.parseColor("#FF4444"))
//                }
            }
        })
        addItemViewDelegate(object : ItemViewDelegate<PmTaskContent> {
            override fun getItemViewLayoutId(): Int = R.layout.item_maintain_2

            override fun isForViewType(item: PmTaskContent, position: Int): Boolean =
                "MAINTAING" == item.taskStepExcuteStatus && "签字确认" != item.type

            override fun convert(holder: ViewHolder, t: PmTaskContent, position: Int) {
                holder.setText(R.id.item_maintain_2_index, "${position + 1}")
                holder.setText(R.id.item_maintain_2_title, t.title)
            }
        })
        addItemViewDelegate(object : ItemViewDelegate<PmTaskContent> {
            override fun getItemViewLayoutId(): Int = R.layout.item_maintain_3

            override fun isForViewType(item: PmTaskContent, position: Int): Boolean =
                "NOTSTART" == item.taskStepExcuteStatus && "签字确认" != item.type

            override fun convert(holder: ViewHolder, t: PmTaskContent, position: Int) {
                holder.setText(R.id.item_maintain_3_index, "${position + 1}")
                holder.setText(R.id.item_maintain_3_title, t.title)
            }
        })
        addItemViewDelegate(object : ItemViewDelegate<PmTaskContent> {
            override fun getItemViewLayoutId(): Int = R.layout.item_maintain_4

            override fun isForViewType(item: PmTaskContent, position: Int): Boolean =
                ("签字确认" == item.type || "维护总结" == item.type) && "COMPLETE" != item.taskStepExcuteStatus

            override fun convert(holder: ViewHolder, item: PmTaskContent, position: Int) {
                holder.setText(R.id.item_maintain_4_title, item.title)
                if ("NOTSTART" == item.taskStepExcuteStatus) {
                    holder.setBackgroundColor(
                        R.id.item_maintain_4_root,
                        Color.parseColor("#FFFFFF")
                    )
                    holder.setTextColor(R.id.item_maintain_4_title, Color.parseColor("#333333"))
                } else {
                    holder.setBackgroundColor(
                        R.id.item_maintain_4_root,
                        Color.parseColor("#409CFA")
                    )
                    holder.setTextColor(R.id.item_maintain_4_title, Color.parseColor("#FFFFFF"))
                }
            }
        })
        addItemViewDelegate(object : ItemViewDelegate<PmTaskContent> {
            override fun getItemViewLayoutId(): Int = R.layout.item_maintain_5

            override fun isForViewType(item: PmTaskContent, position: Int): Boolean =
                "签字确认" == item.type && "COMPLETE" == item.taskStepExcuteStatus && item.label?.isNotEmpty() ?: false

            override fun convert(holder: ViewHolder, item: PmTaskContent, position: Int) {
                holder.setImage(
                    R.id.item_maintain_5_image,
                    "${MyApplication.baseUrl}/uptime/api/w/files/preview/${item.label}"
                )
                holder.setText(R.id.item_maintain_5_time_tv, item.updateTime)
            }
        })
    }

}